package com.pingan.pastry.common.util;

import org.apache.commons.codec.binary.Hex;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

    public static String encrypt(String str) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] bytes = md5.digest(str.getBytes());
        return new String(new Hex().encode(bytes));
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        String mm = MD5Util.encrypt("lll");
        String nn = MD5Util.encrypt("longcheng261");
        System.out.println("密码："+mm);
        System.out.println(mm.length());

        System.out.println("密码："+nn);
        System.out.println(nn.length());


        String mm1 = MD5Util.encrypt("lll");

        System.out.println("密码1："+mm1);
        System.out.println(mm1.length());

    }

}
